package com.xwj.back.service.impl.user.detail;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xwj.back.mapper.UserMapper;
import com.xwj.back.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        User user = userMapper.selectOne(wrapper);
        if(user == null) {
            System.out.println("用户不存在!");
            return null;
        }
        return new UserDetailsImpl(user);
    }
}
